import { defineStore } from "pinia";
import { C1API, C2API, C3API } from '@/network/product/attr';
import type { CategoryResponseData } from "@/network/product/attr/type";
import type { CategoryState } from "./types/type";
export const useCategoryStore = defineStore('category', {
    state(): CategoryState {
        return {
            c1Arr: [],
            c1Id: '', // 一级分类id
            c2Arr: [],
            c2Id: '',
            c3Arr: [],
            c3Id: ''
        }
    },
    actions: {
       async getC1() {
            const res: CategoryResponseData = await C1API()
            // console.log(res);
            if (res.code === 200) {
                this.c1Arr = res.data
            }
        },
       async getC2() {
            const res: CategoryResponseData = await C2API(this.c1Id)
            // console.log(res);
            if (res.code === 200) {
                this.c2Arr = res.data
            }
        },
        async getC3() {
            const res: CategoryResponseData = await C3API(this.c2Id)
            // console.log(res);
            if (res.code === 200) {
                this.c3Arr = res.data
            }
            
        }
    }
})